package com.gu.auxiliaryToolsClass;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.BrokenBarrierException;
import java.util.concurrent.CyclicBarrier;

/**
 * @Author: gusongliao
 * @Description: CyclicBarrier 示例 演示集齐七龙珠召唤神龙
 * @createDate 2023/05/28 16:52
 */
public class CyclicBarrierDemo {

    private static int NUMBER = 7;

    public static void main(String[] args) {

        CyclicBarrier cyclicBarrier = new CyclicBarrier(NUMBER, new Thread(() -> {
            System.out.println("召唤神龙------------ 龍 ");
        }));

        for (int i = 1; i <= NUMBER; i++) {
            new Thread(() -> {
                System.out.println("找到了 " + Thread.currentThread().getName() + " 星龙珠");

                // 等待
                try {
                    cyclicBarrier.await();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                } catch (BrokenBarrierException e) {
                    e.printStackTrace();
                }
            }, String.valueOf(i)).start();
        }

    }
}
